package com.future.mayi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.future.mayi.R;
import com.future.mayi.model.SortParentModel;
import com.future.mayi.view.xrecyclerview.XRecyclerView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class CategoryParentAdapter extends BaseRecyclerViewAdapter<SortParentModel.item> {

    private int curPosition = 0;

    private String curId = "";

    public CategoryParentAdapter(Context context, XRecyclerView xRecyclerView) {
        super(context, null, xRecyclerView);
    }


    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(getView(parent, R.layout.item_shop_category_parent));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ItemViewHolder viewHolder = (ItemViewHolder) holder;
        SortParentModel.item model = getItem(position);
        viewHolder.tvName.setText(model.getName());
        if (curPosition == position) {
            viewHolder.tvName.setTextColor(mContext.getResources().getColor(R.color.main_color));
            viewHolder.vTag.setVisibility(View.VISIBLE);
        } else {
            viewHolder.tvName.setTextColor(mContext.getResources().getColor(R.color.black));
            viewHolder.vTag.setVisibility(View.GONE);
        }
        viewHolder.itemView.setTag(position);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mOnItemClickListener.OnItem(view, position);
            }
        });
    }

    public void setCurPosition(int curPosition) {
        this.curPosition = curPosition;
        curId = getItem(curPosition).getCate_id();
        notifyDataSetChanged();
    }

    public String getCurId() {
        return curId;
    }

    class ItemViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.item_shop_category_parent_tv)
        TextView tvName;
        @BindView(R.id.item_shop_category_parent_v)
        View vTag;


        public ItemViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
